home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * overlay: an openGL-Xlib "overlay" example program.
- *
- * overlay is the openGL "after" version of the IrisGL
- * "before" program, ~4Dgifts/examples/grafix/overlay.c
- *
- * - b key toggles the bell off or on.
- * - Esc key: exit
- *
- * overlay demonstrates defining an overlay window coincident with
- * the GL window, changing size as the GL window does, etc. both
- * these windows are created as children of a parent X window. two
- * window attribute lists are defined for each child window--in the
- * GL window's case, if the requested GLX_BUFFER_SIZE is less than
- * 12 (this will be a doublebuffered colormap window where we want
- * to use more than 16 colors if possible), then we request a visual
- * from glXChooseVisual with only DOUBLEBUFFER specified to get back
- * the deepest visual the current system has. similiarly for the
- * overlay window, if a request for GLX_LEVEL of 2 fails, then we
- * revert to asking for GLX_LEVEL of 1 and if this fails, exit the
- * program.
- *
- * ratmandu -- ported to openGL, aug, '93
- */
-
- #include <stdio.h>
- #include <GL/glx.h>
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <stdlib.h>
- #include <X11/keysym.h>
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
-
- #define top 0 /* parent X window array index */
- #define GLwin 1 /* doublebuffer'd colormap GL win index */
- #define OLwin 2 /* overlay (LEVEL 2 or 1) GL win index */
- #define WINMAX 3 /* number of unique windows */
-
- static void openwindow(char *);
- static void initGL(void);
- static void clean_exit(void);
- static void drawball(void);
- static void drawovers(void);
- static int rampup(short, short, short, short, short, short, short, short);
- void Winset(int);
-
- Display *dpy; /* X server connection */
- Atom del_atom; /* for possibility of WM killing app */
- int xsize, ysize; /* current size-of-window keepers */
- Window glwins[WINMAX]; /* array for GL/OL window ids */
- GLXContext glcontexts[WINMAX]; /* array for GL/OL window context ids */
- GLUquadricObj *quadObj; /* used to make the two spheres with */
- XEvent event; /* needs to be global for XIfEvent */
- int bell; /* flag for turning off/on Xbell() */
- int BIGcmap; /* for low-end machines w/less colors */
- unsigned short mycolortbl[83]; /* color array for when ball falls */
- int black, red, green, yellow, blue, /* cmap indices identifiers */
- magenta, cyan, white, beige;
- int OLred, OLgreen, OLcyan; /* overlay color handles saved out by */
- /* returned vals from XAllocNamedColor*/
-
-
-
- main (int argc, char **argv)
- {
- int myExpose, myKeyPress; /* store which events occur */
- int firstPass; /* for initially turning on the bell */
- KeySym keysym;
- char buf[4];
-
-
-
- myExpose = myKeyPress = GL_FALSE;
- firstPass = GL_TRUE;
-
- openwindow(argv[0]); /* define/setup window stuff */
-
- initGL(); /* initialize GL stuff */
-
- if (BIGcmap) /* depending on the visual's */
- rampup (12, 82, 255, 255, 0, 255, 0, 0); /* returned colormap_size, */
- else /* we'll either make a big */
- rampup (5, 15, 255, 255, 0, 255, 0, 0); /* or a small color ramp */
-
- while (GL_TRUE) { /* main loop: get/process input */
-
- glFlush(); /* For proper DGL performance */
-
- /* this "do while" loop does the `get events' half of the "get events,
- * process events" action of the infinite while. this is to ensure
- * the event queue is always drained before the events that have come
- * in are processed.
- */
- while (XEventsQueued(dpy,QueuedAfterReading)) {
- /* XEventsQueued(dpy,QueuedAfterReading)
- * is like qtest()--it only tells you if
- * there're any events presently in the
- * queue. it does not disturb the event
- * queue's contents in any way.
- */
-
- XNextEvent(dpy, &event);
- switch (event.type) {
-
- /* "Expose" events are sort of like "REDRAW" in gl-speak in
- * terms of when a window becomes visible, or a previously
- * invisible part becomes visible.
- */
- case Expose: /* Exposures */
- myExpose = GL_TRUE;
- break;
-
- /* "ConfigNotify" events are like "REDRAW" in terms of changes
- * to a window's size or position. Instead of making a
- * separate "myConfigure" flag, we'll simply redefine the
- * window's new size now and set the "myExpose" flag which
- * will come back around and redraw everything.
- */
- case ConfigureNotify: /* Resize GL manually */
- if (event.xconfigure.window == glwins[top]) {
- /* save the changed width/height of the parent X window */
- xsize = event.xconfigure.width;
- ysize = event.xconfigure.height;
- XMoveResizeWindow(dpy, glwins[OLwin], 0,0, xsize,ysize);
- XMoveResizeWindow(dpy, glwins[GLwin], 0,0, xsize,ysize);
- XFlush(dpy);
- Winset(OLwin);
- glViewport(0, 0, xsize-1, ysize-1);
- glLoadIdentity();
- gluOrtho2D(0.0, 1.0, 0.0, 1.0);
- Winset(GLwin);
- glViewport(0, 0, xsize-1, ysize-1);
- glLoadIdentity();
- gluOrtho2D(0.0, 1.0, 0.0, 1.0);
- myExpose = GL_TRUE;
- }
- break;
-
-
- /* "ClientMessage" is generated if the WM itself is being
- * gunned down and sends an exit signal to any running prog.
- */
- case ClientMessage:
- if (event.xclient.data.l[0] == del_atom)
- clean_exit();
- break;
-
-
- /* "KeyPress" events are those that would be generated before
- * whenever queueing up any KEYBD key via qdevice.
- */
- case KeyPress:
- /* save out which unmodified key (i.e. the key was
- * not modified w/something like "Shift", "Ctrl",
- * or "Alt") got pressed for use below.
- */
- XLookupString((XKeyEvent *)&event, buf, 4, &keysym, 0);
- myKeyPress = GL_TRUE;
- break;
-
- } /* end switch (event.type) */
-
-
- } /* end while (XEventsQueued(dpy,QueuedAfterReading)) { */
-
- /* On an "Expose" event, [re]draw the just opened, popped, moved,
- * resized or de-iconized window
- */
- if (myExpose) {
- if (firstPass) {
- bell = GL_TRUE;
- firstPass = GL_FALSE;
- }
- Winset(OLwin); /* redraw overlay window */
- drawovers();
- Winset(GLwin); /* redraw GL window */
- drawball(); /* draw the GL stuff */
- myExpose = GL_FALSE; /* reset flag--queue now empty */
- }
-
- /*
- * On a keypress of
- * - b key toggles the bell in the GL window.
- * - Esc key: exit.
- */
- if (myKeyPress) {
-
- if (keysym == XK_b) {
- bell = (bell == GL_TRUE) ? GL_FALSE : GL_TRUE;
- fprintf(stderr,"bell now = %d\n", bell);
- } else if (keysym == XK_Escape) {
- clean_exit();
- }
- myKeyPress = GL_FALSE; /* reset flag--queue now empty */
- }
-
- drawball();
- }
- }
-
-
- #define QTEST() XEventsQueued(dpy, QueuedAfterFlush)
-
-
- /* drawball: the only drawback about this way of drawing the moving "ball"
- * is any time *any* event occurs--manipulating the window,
- * pressing a mouse button or keyboard key--logic flow will
- * entirely drop out of drawball, read the event, and then come
- * back into drawball not picking up where it left off, but
- * starting all over again.... for anyone who likes puzzles, if
- * you work up a a swank solution to this so the ball doesn't
- * have to "restart" each time, i'd appreciate "hearing" from
- * you at dave@sgi.com.
- */
- static void drawball(void) {
-
- float heat, rate;
- short val = 0;
- int i, j, xpos, ypos;
- float yspd = 0.0, yaccel = -1.0, yacc = -.4, yreflect = -0.6;
-
- for (i = j = 34; i<940 && j<940 && !(QTEST()); i = i+6, j = j+6) {
- glIndexi(blue); /* roll the ball up and to the right */
- glClear(GL_COLOR_BUFFER_BIT);
- if (bell && ((i==210) || (i==510) || (i==810)))
- XBell(dpy, 80); /* ring bell if specified */
- if ((i>250) && (i<530)) /* the ball gets to the */
- glIndexi(beige); /* next rectangle, as well */
- else if ((i>530) && (i<810)) /* change the ball's color */
- glIndexi(magenta);
- else if (i>810)
- glIndexi(white);
- else
- glIndexi(yellow);
-
- glPushMatrix();
- glTranslatef((float)i/940.0, (float)j/940.0, 0.0);
- gluDisk(quadObj, 0.0, 0.035, 32, 1);
- glPopMatrix();
-
- glXSwapBuffers(dpy, glwins[GLwin]);
- }
-
- yspd = 0.0;
- if (BIGcmap) {
- heat = 82.0;
- rate = 1.0;
- } else {
- heat = 15.0;
- rate = 0.144;
- }
- for (xpos=1, ypos=990; ypos>=25 && !(QTEST()); xpos++, ypos+=yspd) {
- glIndexi(blue); /* drop the ball back to the bottom */
- glClear(GL_COLOR_BUFFER_BIT);
- heat = heat - rate;
- glIndexi(mycolortbl[(int) heat]); /* change the ball's color */
- yspd += yacc; /* as it falls */
-
- glPushMatrix();
- glTranslatef(0.96, ypos/990.0, 0.0);
- gluDisk(quadObj, 0.0, 0.035, 32, 1);
- glPopMatrix();
-
- glXSwapBuffers(dpy, glwins[GLwin]);
- }
-
- yspd = -60.0;
- for (xpos=990, ypos=34; xpos >= 0 && !(QTEST()); xpos -= 5) {
- if (ypos <= 34) /* roll the ball back to the beginning */
- yspd *= yreflect; /* and keep updating its' */
- glIndexi(blue); /* bounce-ability per frame */
- glClear(GL_COLOR_BUFFER_BIT);
- glIndexi(yellow);
- ypos += yspd;
- yspd += yaccel;
-
- glPushMatrix();
- glTranslatef(xpos/990.0, ypos/990.0, 0.);
- gluDisk(quadObj, 0.0, 0.035, 32, 1);
- glPopMatrix();
-
- glXSwapBuffers(dpy, glwins[GLwin]);
- }
- }
-
-
-
- /* clean up before exiting
- */
- static void clean_exit(void)
- {
- Winset(OLwin);
- glIndexi(0);
- glClear(GL_COLOR_BUFFER_BIT);
- Winset(GLwin);
- XCloseDisplay(dpy);
- exit(0);
- }
-
-
-
- Colormap GLcmap, OLcmap; /* need both these handles in openwindow & initGL */
-
- /* with the GL and overlay windows, we're defining two kinds of visuals:
- * GLwinattribList and OLwinattribList are our "first choices", but if
- * we're on minimum (8-bit) configuration systems, then we'll settle
- * for whatever the deepest visual is available for the GL window
- * (GLwinattribList2) and for a LEVEL 1 visual for overlays
- * (OLwinattribList2) which, apparently, if nothing else, is ALWAYS
- * supposed to exist on ANY sgi machine.
- */
- static int GLwinattribList[] = { GLX_DOUBLEBUFFER, /* first choices */
- GLX_BUFFER_SIZE, 12,
- None };
- static int OLwinattribList[] = { GLX_LEVEL, 2, None };
-
- static int GLwinattribList2[] = { GLX_DOUBLEBUFFER, /* fallbacks */
- None };
- static int OLwinattribList2[] = { GLX_LEVEL, 1, None };
-
-
- /* WaitForNotify:
- * used to make sure the MapWindow() calls inside openwindow() occur
- * beFORE glXMakeCurrent() is invoked so as to avoid a race condition.
- */
- static Bool WaitForNotify(Display *d, XEvent *e, char *arg) {
- return (e->type == MapNotify) && (e->xmap.window == (Window)arg);
- }
-
-
- /* openwindow:
- * open a window. in this case, make an X window that is the parent of
- * both the GL window and the overlay window. There is a bug in X where,
- * even though one defines the events one is interested in reading via
- * the XSetWindowAttributes structure and then including that structure
- * as the last parameter to the XCreateWindow() call, the events
- * nevertheless get dropped on the floor and are not picked up. hence
- * the need to call XSelectInput() explicitly. this shud NOT need to be
- * done, but at this point the hack inclusion of XSelectInput is necessary.
- */
- static void openwindow(char *progname)
- {
- XSizeHints Winhints; /* used to fix window size */
- XVisualInfo *GLvi, *OLvi; /* visual for the GL and overlay window */
- XSetWindowAttributes GLswa, OLswa; /* win attributes structures */
- int scrnnum; /* X screen number */
- int xorig, yorig; /* window (upper-left) origin */
- int scrnheight;
-
-
- /* Connect to the X server and get screen info */
- if ((dpy = XOpenDisplay(NULL)) == NULL) {
- fprintf(stderr, "%s: cannot connect to X server %s\n",
- progname, XDisplayName(NULL));
- exit(1);
- }
- scrnnum = DefaultScreen(dpy);
- scrnheight = DisplayHeight(dpy, scrnnum);
-
- xorig = 0; yorig = 0; /* define window initial size */
- xsize = 200; ysize = 200;
-
- /* first create the top level X window which will be the parent to both
- * the singlebuffer and doublebuffer rendering windows
- */
- glwins[top] = XCreateSimpleWindow(dpy, RootWindow(dpy, scrnnum),
- xorig, yorig, xsize, ysize, 0, 0, 0);
- if (!(glwins[top])) {
- fprintf(stderr,"%s: couldn't create \"parent\" X window\n",progname);
- exit(1);
- }
- /* including this call to XSelectInput shud not be necessary, but there's
- * a bug, so we have to resort to this hackaround.
- */
- XSelectInput(dpy, glwins[top], StructureNotifyMask |
- ExposureMask | KeyPressMask);
-
- /* define the string that will show up in the window title bar (and icon) */
- XStoreName(dpy, glwins[top], "overlay demo program");
-
- /* Now specify the values for the Window Aspect Hints we want to
- * enforce so that the aspect ratio of 1 to 1 will always be
- * maintained when the parent X window is resized. Also specify
- * the minimum size (80x80) we will allow this window to shrink to.
- */
- Winhints.width = xsize; /* specify desired x/y size of window */
- Winhints.height = ysize;
- Winhints.min_width = xsize;
- Winhints.max_width = scrnheight-1;
- Winhints.min_height = ysize;
- Winhints.max_height = scrnheight-1;
- Winhints.min_aspect.x = 1;
- Winhints.max_aspect.x = 1;
- Winhints.min_aspect.y = 1;
- Winhints.max_aspect.y = 1;
- /* set the corresponding flags */
- Winhints.flags = USSize|PMaxSize|PMinSize|PAspect;
- XSetWMNormalHints(dpy, glwins[top], &Winhints);
-
- /* now define and create the GL window and it's accompanying overlay win */
-
- /* first, get the appropriate visuals */
- GLvi = glXChooseVisual(dpy, scrnnum, GLwinattribList);
- if (GLvi == NULL) { /* if NULL, our request failed--try a simpler one */
- fprintf(stderr, "Unable to obtain a 12-bit deep doublebuffered ");
- fprintf(stderr, "colorindex visual\n");
- fprintf(stderr, "Now will try for max depth avail on this system...\n");
- GLvi = glXChooseVisual(dpy, scrnnum, GLwinattribList2);
- }
- /* hackalong to test for 8-bit systems--if we're limited to 16
- * colors then just define the actual colors we use in the
- * first five colormap indices.
- */
- if (BIGcmap = (GLvi->colormap_size > 16) ? GL_TRUE : GL_FALSE) {
- black = 0;
- red = 1;
- green = 2;
- yellow = 3;
- blue = 4;
- magenta = 5;
- cyan = 6;
- white = 7;
- beige = 8;
- } else {
- beige = 0;
- white = 1;
- magenta = 2;
- yellow = 3;
- blue = 4;
- }
- OLvi = glXChooseVisual(dpy, DefaultScreen(dpy), OLwinattribList);
- if (OLvi == NULL) { /* if NULL, our request failed--try a simpler one */
- fprintf(stderr, "Unable to obtain a LEVEL 2 overlay visual\n");
- fprintf(stderr, "Now will try for LEVEL 1 overlay visual...\n");
- OLvi = glXChooseVisual(dpy, scrnnum, OLwinattribList2);
- if (OLvi == NULL) {
- fprintf(stderr, "sorry, no \"overlay\" bitplanes on this system\n");
- clean_exit();
- }
- }
-
- /* now create the appropriate GL contexts */
- glcontexts[GLwin] = glXCreateContext(dpy, GLvi, 0, GL_TRUE);
- glcontexts[OLwin] = glXCreateContext(dpy, OLvi, None, GL_TRUE);
-
- /* create the two colormaps */
- GLcmap = XCreateColormap(dpy, RootWindow(dpy, GLvi->screen),
- GLvi->visual, AllocAll);
- if (GLcmap == NULL) {
- fprintf(stderr, "ERROR: no writable \"GLwin colormap\"(???)\n");
- clean_exit();
- }
- OLcmap = XCreateColormap(dpy, RootWindow(dpy, OLvi->screen),
- OLvi->visual, AllocNone);
- if (OLcmap == NULL) {
- fprintf(stderr, "ERROR: no writable \"Overlay colormap\"\n");
- clean_exit();
- }
-
- /* now create both windows */
- GLswa.border_pixel = 0;
- GLswa.colormap = GLcmap;
- /* express interest in events */;
- GLswa.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
- glwins[GLwin] = XCreateWindow(dpy, glwins[top],
- xorig, yorig, xsize, ysize,
- 0, GLvi->depth, InputOutput, GLvi->visual,
- CWBorderPixel|CWColormap|CWEventMask, &GLswa);
- OLswa.border_pixel = 0;
- OLswa.colormap = OLcmap;
- OLswa.win_gravity = UnmapGravity;
- OLswa.bit_gravity = NorthWestGravity;
- OLswa.background_pixel = BlackPixel(dpy, OLvi->screen);
- /* express interest in events */;
- OLswa.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
- glwins[OLwin] = XCreateWindow(dpy, glwins[top],
- xorig, yorig, xsize, ysize,
- 0, OLvi->depth, InputOutput, OLvi->visual,
- CWBorderPixel|CWColormap|CWEventMask, &OLswa);
-
- /* now map all three windows using XIfEvent to prevent race conditions
- * for the children GL and overlay windows (which are the only ones we'll
- * ever invoke in glXMakeCurrent())
- */
- XMapWindow(dpy, glwins[OLwin]);
- XIfEvent(dpy, &event, WaitForNotify, (char*)glwins[OLwin]);
- XMapWindow(dpy, glwins[GLwin]);
- XIfEvent(dpy, &event, WaitForNotify, (char*)glwins[GLwin]);
- XMapWindow(dpy, glwins[top]);
-
- /* now connect the context to the GL window */
- if (!glXMakeCurrent(dpy, glwins[GLwin], glcontexts[GLwin]) == GL_TRUE) {
- fprintf(stderr, "error w/glXMakeCurrent: cudn't set");
- fprintf(stderr, " context to the GL window\n");
- exit(-1);
- }
-
- /* ensure the GL colormap is installed for this app */
- XSetWMColormapWindows(dpy, glwins[top], glwins, WINMAX);
-
- /* express interest in WM being able to kill this app */
- if ((del_atom = XInternAtom(dpy, "WM_DELETE_WINDOW", True)) != None)
- XSetWMProtocols(dpy, glwins[top], &del_atom, 1);
-
- glFlush();
- }
-
-
- void
- initGL(void)
- {
- XColor colorstruct;
- XColor spix, pixel;
- int OLcolorfound;
-
-
- bell = GL_FALSE;
-
- /* define color map values for the GL window */
- colorstruct.pixel = yellow;
- colorstruct.red = 65535;
- colorstruct.green = 65535;
- colorstruct.blue = 0;
- colorstruct.flags = DoRed | DoGreen | DoBlue;
- XStoreColor(dpy, GLcmap, &colorstruct);
- colorstruct.pixel = blue;
- colorstruct.red = 0;
- colorstruct.green = 0;
- colorstruct.blue = 65535;
- colorstruct.flags = DoRed | DoGreen | DoBlue;
- XStoreColor(dpy, GLcmap, &colorstruct);
- colorstruct.pixel = magenta;
- colorstruct.red = 65535;
- colorstruct.green = 0;
- colorstruct.blue = 65535;
- colorstruct.flags = DoRed | DoGreen | DoBlue;
- XStoreColor(dpy, GLcmap, &colorstruct);
- colorstruct.pixel = white;
- colorstruct.red = 65535;
- colorstruct.green = 65535;
- colorstruct.blue = 65535;
- colorstruct.flags = DoRed | DoGreen | DoBlue;
- XStoreColor(dpy, GLcmap, &colorstruct);
- colorstruct.pixel = beige;
- colorstruct.red = 50885; /* was [198,113,133] rgb triplet */
- colorstruct.green = 29040;
- colorstruct.blue = 29040;
- colorstruct.flags = DoRed | DoGreen | DoBlue;
- XStoreColor(dpy, GLcmap, &colorstruct);
-
- /* now try to get the overlay win's `red', `green', and `cyan' pixel values--
- * we'll need these to set the read-only colormap indices for overlay drawing
- */
- if (OLcolorfound = XAllocNamedColor(dpy, OLcmap, "red", &spix, &pixel))
- OLred = pixel.pixel;
- else
- fprintf(stderr, "Bummer--no `red' color found for overlay drawing\n");
- if (OLcolorfound = XAllocNamedColor(dpy, OLcmap, "green", &spix, &pixel))
- OLgreen = pixel.pixel;
- else
- fprintf(stderr, "Bummer--no `green' color found for overlay drawing\n");
- if (OLcolorfound = XAllocNamedColor(dpy, OLcmap, "cyan", &spix, &pixel))
- OLcyan = pixel.pixel;
- else
- fprintf(stderr, "Bummer--no `cyan' color found for overlay drawing\n");
-
- quadObj = gluNewQuadric();
- gluQuadricDrawStyle(quadObj,GLU_FILL);
-
- XMoveResizeWindow(dpy, glwins[GLwin], 0, 0, xsize, ysize);
- XFlush(dpy);
- glViewport(0, 0, xsize-1, ysize-1);
- glLoadIdentity();
- gluOrtho2D(0.0, 1.0, 0.0, 1.0);
-
- /* clear the GL window buffer's "background" */
- glClearIndex(blue);
- glClear(GL_COLOR_BUFFER_BIT);
-
- Winset(OLwin); /* get into the overlay[/popup] bitplanes */
- XMoveResizeWindow(dpy, glwins[OLwin], 0, 0, xsize, ysize); /* to draw */
- XFlush(dpy); /* their */
- glViewport(0, 0, xsize-1, ysize-1); /* contents*/
- glLoadIdentity();
- gluOrtho2D(0.0, 1.0, 0.0, 1.0);
- drawovers();
-
- Winset(GLwin); /* now set context back to the GL window */
- glFlush();
- }
-
-
- char *typeToName[] = {
- "parent window",
- "Cmap double buffer",
- "Cmap overlay buffer",
- };
-
-
- /* A little helper wrapper for glXMakeCurrent.
- * passes the index to jointly access the windows and contexts array and
- * checks the return value. This makes the call to begin GL drawing a
- * little simpler. Building in such automatic error checking is always a
- * "smooth move" (*not* like the cancerously-mutant human with the enlarged
- * proboscis plastered all over the place urging people to be likewise
- * smoothly cancerous and hardly cool).
- */
- void Winset(int type)
- {
- int rv;
-
- XSync(dpy,GL_FALSE);
- rv = glXMakeCurrent(dpy, glwins[type], glcontexts[type]);
- if (rv == GL_FALSE) {
- fprintf(stderr, "glXMakeCurrent failed for a %s-type window\n",
- typeToName[type]);
- exit(-1);
- }
- }
-
-
- static void drawovers(void) {
-
- glClearIndex(0);
- glClear(GL_COLOR_BUFFER_BIT);
- glIndexi(OLred);
- glRectf(.215, .215, .285, .285); /* & draw some rectangles for */
- glIndexi(OLgreen); /* the ball to roll underneath*/
- glRectf(.515, .515, .585, .585);
- glIndexi(OLcyan);
- glRectf(.815, .815, .885, .885);
- glIndexi(OLgreen);
- glRectf(.877, .527, .947, .597);
- glRectf(.733, .527, .805, .597);
- glRectf(.949, .455, 1.019, .525);
- glRectf(.805, .455, .875, .525);
- glRectf(.661, .455, .731, .525);
- glRectf(.877, .383, .947, .453);
- glRectf(.733, .383, .805, .453);
- glRectf(.589, .383, .659, .453);
- glRectf(.949, .311, 1.019, .381);
- glRectf(.877, .239, .947, .309);
- glRectf(.805, .311, .875, .381);
- glRectf(.733, .239, .803, .309);
- glRectf(.661, .311, .731, .381);
- glRectf(.589, .239, .659, .309);
- glRectf(.519, .311, .587, .381);
- glRectf(.447, .239, .517, .309);
- glRectf(.661, .167, .731, .237);
- glRectf(.519, .167, .587, .237);
- glRectf(.375, .167, .445, .237);
- glRectf(.447, .095, .517, .165);
- glRectf(.589, .095, .659, .165);
- glRectf(.661, .023, .731, .093);
- glRectf(.519, .023, .587, .093);
- glRectf(.375, .023, .445, .093);
- }
-
-
- /* rampup:
- * makes an interpolated color ramp based on the DDA algorithm from the
- * 1st arguement's index to the 2nd. 3rd and 4th are red's low and hi
- * indices (5&6 green's, 7&8 blue's).
- */
-
- static int rampup(short first_lutv, short last_lutv, /*start/end ramp vals*/
- short minR, short maxR, short minG, short maxG, /* lo/hi rgb vals */
- short minB, short maxB)
- {
- unsigned short len_red, len_green, len_blue, /* length of each color */
- i; /* counter for number of steps */
-
- float red, gre, blu; /* lut values */
- float rdx, gdx, bdx, /* sizes of rgb increments */
- r, g, b, /* a position on the ramp */
- steps; /* # of steps along the ramp @ which */
- /* intensity assignments will be made */
- XColor colorstruct;
-
- steps = (float) (last_lutv-first_lutv + 1); /*determine length of ramp*/
-
- len_red = (maxR - minR); /* determine length of red */
- len_green = (maxG - minG); /* determine length of green */
- len_blue = (maxB - minB); /* determine length of blue */
-
- rdx = (float) len_red / steps; /* compuke step */
- gdx = (float) len_green / steps; /* sizes of r g */
- bdx = (float) len_blue / steps; /* and b values */
- r = minR; /* assign starting */
- g = minG; /* indices for each */
- b = minB; /* color value */
-
- for (i = first_lutv; i <= last_lutv; i++) {
- red = r/255.0; /* round off */
- gre = g/255.0; /* given r g */
- blu = b/255.0; /* b value */
- mycolortbl[i] = i;
- colorstruct.pixel = i;
- colorstruct.red = (unsigned short) (red*65535); /* remember, */
- colorstruct.green = (unsigned short) (gre*65535); /* we've got */
- colorstruct.blue = (unsigned short) (blu*65535); /* two bytes-*/
- colorstruct.flags = DoRed | DoGreen | DoBlue; /* worth */
- XStoreColor(dpy, GLcmap, &colorstruct);
- r += rdx; /* increment */
- g += gdx; /* color in- */
- b += bdx; /* dices */
- }
- }
-